//
//  QLVisitorView.swift
//  WeiBo01
//
//  Created by 黄跃奇 on 16/9/21.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class QLVisitorView: UIView {
    //懒加载控件
    //旋转视图
    private lazy var cycleImageView: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    //罩层
    private lazy var maskImageView: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    //主页
    private lazy var iconImageView: UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    //未登录信息
    private lazy var messageLabel: UILabel = {
        let label = UILabel()
        label.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
        label.font = UIFont.systemFont(ofSize: 13)
        label.textColor = UIColor.darkGray
        //显示多行
        label.numberOfLines = 0
        //居中
        label.textAlignment = .center
        return label
    }()
    //登录按钮
    private lazy var loginButton: UIButton = {
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), for: .normal)
        button.setTitle("登录", for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        //去掉点击的高亮效果
        button.adjustsImageWhenHighlighted = false
        return button
    }()
    //注册按钮
    private lazy var registerButton: UIButton = {
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: "common_button_white_disable"), for: .normal)
        button.setTitle("注册", for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        //去掉点击的高亮效果
        button.adjustsImageWhenHighlighted = false
        return button
    }()
    

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        backgroundColor = UIColor.yellow
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        
        //设置背景颜色
        backgroundColor = UIColor(white: 237/255, alpha: 1.0)
        
        //添加控件
        addSubview(cycleImageView)
        addSubview(maskImageView)
        addSubview(iconImageView)
        addSubview(messageLabel)
        addSubview(loginButton)
        addSubview(registerButton)
        
        //设置约束
        cycleImageView.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        maskImageView.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        iconImageView.snp_makeConstraints { (make) in
            make.center.equalTo(cycleImageView)
        }
        messageLabel.snp_makeConstraints { (make) in
            make.top.equalTo(cycleImageView.snp_bottom)
            make.centerX.equalTo(cycleImageView)
            make.width.equalTo(224)
        }
        loginButton.snp_makeConstraints { (make) in
            make.top.equalTo(messageLabel.snp_bottom).offset(10)
            make.leading.equalTo(messageLabel.snp_leading)
            make.size.equalTo(CGSize(width: 100, height: 35))
        }
        registerButton.snp_makeConstraints { (make) in
            make.top.equalTo(loginButton)
            make.trailing.equalTo(messageLabel.snp_trailing)
            make.size.equalTo(CGSize(width: 100, height: 35))
        }
        
    }
    
    //开启核心动画
    private func startAnimation() {
        
        //创建核心动画对象
        let anim = CABasicAnimation()
        //执行到的目的地
        anim.toValue = 2 * M_PI
        //动画执行时长
        anim.duration = 15
        //动画执行次数
        anim.repeatCount = MAXFLOAT
        cycleImageView.layer.add(anim, forKey: nil)
    }

}





